#ifndef THIRDPARTY_LOGGING_FIXED_BUFFER_H_
#define THIRDPARTY_LOGGING_FIXED_BUFFER_H_
#pragma once
#include <stdint.h>
#include <string>
#include <cstring>
#include <memory>
namespace logging {
template <uint32_t SIZE>
class FixedBuffer {
 public:
  FixedBuffer(): current_(buffer_) {
  }
  char* GetCurrent() {
    return current_;
  }
  uint32_t RemainLen() {
    return End() - current_;
  }
  char* End() {
    return buffer_ + SIZE;
  }
  bool Append(const char* s, uint32_t s_len) {
    if (RemainLen() > s_len) {
      memcpy(current_, s, s_len);
      current_ += s_len;
      *current_ = '\0';
      return true;
    }
    return false;
  }
  bool Append(char s) {
    if (RemainLen() > 1) {
      *current_++ = s;
      *current_ = '\0';
      return true;
    }
    return false;
  }
  uint32_t Size() const {
    return current_ - buffer_;
  }
  void Reset() {
    current_ = buffer_;
  }
  std::string DebugString() const {
    return std::string(buffer_, current_ - buffer_);
  }
  char* CStr() {
    return buffer_;
  }
  void MoveCursor(size_t len) {
    current_ += len;
  }
 private:
  char buffer_[SIZE];
  char* current_;
};

}
#endif  // THIRDPARTY_LOGGING_FIX_BUFFER_H_
